<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>04canvas三角形</title>
</head>
<style>
    canvas{
        border: 1px solid #ccc;
    }
</style>
<body>
    <canvas width="600"height="400"></canvas>
    <script>
        var myCanvas=document.querySelector("canvas");
        var ctx =myCanvas.getContext('2d');
        ctx.moveTo(100,100);
        ctx.lineTo(100,200);
        ctx.lineTo(200,200);
        /*起始点moveTo和lineTo的结束点无法完全闭合 会产生缺角*/
        //ctx.lineTo(100,100);
        /*使用canvas的自动闭合*/
        /*关闭路径*/
        ctx.closePath();
        ctx.lineWidth=10;
        /*描边*/
        ctx.stroke();
        /*填充*/
        ctx.fillStyle='red';
        ctx.fill();
    </script>
</body>
</html>
